<script type="text/javascript">
window.history.forward(1);
</script>
<a href="/" ><div class="topBack"><img src="/images/back_jiantou.png" style="width:40px;height:40px;"></div></a>
<div class="topContent">提交订单</div>
<div class="topRight">&nbsp;</div>
<div class="clear"></div>
<input type="hidden" name="type" value="<?php echo $this->type ?>" id="sale_type">

<?php 
if(!empty($this->preSubmit)){
	$sessionNamespace = new Zend_Session_Namespace('siteid');
	$sessionAddress = $sessionNamespace->address;
	$sessionContact = $sessionNamespace->orderContact;
	$sessionTel = $sessionNamespace->tel;
	
	$orderDetails = $this->preSubmit->orderDetails[0];
	$res = $orderDetails;
	$contact = $res->order_contact;
	$tel = $res->order_tel;
	$address = $res->order_address;
	$delivery = $res->delivery;
	$appointment = $res->svtime;
	$payment = $res->payment;
	$price = $res->price;
	$discount = $res->discount;
	$voucher = $res->voucher;
	$voucherId = $res->voucherid;
	$gift = $res->gift;
	$custprice = $res->custprice;
	$id = $res->id;
	$stime = $res->stime;
	$etime = $res->etime;
	
	$shopDetails = $this->preSubmit->shopDetails[0];
	$shopType = $shopDetails->type;
	if($shopType == 2) {
	  $time_end = '18:00:00';
	} else {
	  $time_end = '21:00:00';
	}
	$nowTime = date('H:i:s');
	$payonline = $shopDetails->payonline;
	$payondelivery = $shopDetails->payondelivery;
	$samedaydelivery = $shopDetails->samedaydelivery;
}else{
	echo '<script type="text/javascript">location.href="/error"</script>';
}
?>

<form action="/order/complete" method="post">
<div id="wrapperCom" class="wrapperComman" style="top:40px;bottom:0px;">
<div style="width:100%;min-height:900px;">
<input type="hidden" name="id" id="orderid" value="<?php echo $id;?>">


<?php 
if($this->type!='advance'){
	if(!empty($contact)&&!empty($tel)){
		echo '
		<div id="address_view">
			<div class="add_left" style="height:60px;" onclick="javascript:edit_address();return false;">
				<div>联系人：'.$contact.'</div>
				<div>联系电话：'.$tel.'</div>
			</div>
			<div class="add_right" style="height:60px;" onclick="javascript:edit_address();return false;">
				<div class="add_edit">></div>
			</div>
			<div class="clear"></div>
			<input  id="username" type="hidden" value="';echo $contact;echo '">
			<input  id="mobile" type="hidden" value="';echo $tel;echo '">
		</div>	
		';
	}else{
	echo '
		<div id="address_edit">
			<div class="cp_name">姓名
				<span>
					<input  class="cp_form_input" id="username" type="text" value="';
					if(!empty($contact)){echo $contact;}
					echo '" name="username" placeholder="收货人姓名">
				</span>
			</div>
			<div class="cp_name">手机
				<span>
					<input  class="cp_form_input" id="mobile" type="text" value="';
					if(!empty($tel)){echo $tel;}
					echo '" name="phone" placeholder="收货人电话号码">
				</span>
			</div>
		</div>';
	}	
}else{//快递单
	if(!empty($sessionContact)&&!empty($sessionTel)&&!empty($sessionAddress)){
		echo '
		<div id="address_view">
			<div class="add_left" style="height:70px;" onclick="javascript:toAddress('.$id.');return false;">
				<div>联系人：'.$sessionContact.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$sessionTel.'</div>
				<div>收货地址：'.$sessionAddress.'</div>
			</div>
			<div class="add_right" style="height:70px;" onclick="javascript:toAddress('.$id.');return false;">
				<div class="add_edit">></div>
			</div>
			<div class="clear"></div>
			<input  id="username" type="hidden" value="';echo $sessionContact;echo '">
			<input  id="mobile" type="hidden" value="';echo $sessionTel;echo '">
			<input  id="presaleAddress" type="hidden" value="';echo $sessionAddress;echo '">
		</div>	
		';
	}else{
		echo '<div onclick="javascript:toAddress('.$id.');return false;" style="padding:10px 20px;font-size:0.9em;">
					<img src="/images/dizhi.jpg">&nbsp;&nbsp;请选择收货地址<span style="float:right;">></span>
			</div>';
	}
}
?>
<?php if($this->type!='advance'): ?>
	<script>
		$('#address_edit').css('border-bottom','2px dashed #C7E2B9');
	</script>
<?php endif;?>
<!--2016 .5.19 by 赵鑫-->
	<?php if($this->type=='advance'):?>
		<div id="address_info" style="display:none;">
			<div class="address_area">上海市
				<?php
				$area = null;
				if($address){
					$addressDetails = null;
					if(strpos($address,'， ')){
						$arr = explode('， ',$address);
						$area = $arr[1];
						$addressDetails = $arr[2];
					}
				}
				?>
				<span>
				<select id="Select1" style="display: none">
					<option value="上海">上海</option>
				</select>
<!--				<select id="Select2" style="display: none"></select>-->
				<select id="Select3">
					<option value="黄浦区"<?php if($area=='黄埔区'){ echo 'selected'; } ?>>黄埔区</option>
					<option value="卢湾区"<?php if($area=='卢湾区'){ echo 'selected'; } ?>>卢湾区</option>
					<option value="徐汇区"<?php if($area=='徐汇区'){ echo 'selected'; } ?>>徐汇区</option>
					<option value="长宁区"<?php if($area=='长宁区'){ echo 'selected'; } ?>>长宁区</option>
					<option value="静安区"<?php if($area=='静安区'){ echo 'selected'; } ?>>静安区</option>
					<option value="普陀区"<?php if($area=='普陀区'){ echo 'selected'; } ?>>普陀区</option>
					<option value="闸北区"<?php if($area=='闸北区'){ echo 'selected'; } ?>>闸北区</option>
					<option value="虹口区"<?php if($area=='虹口区'){ echo 'selected'; } ?>>虹口区</option>
					<option value="杨浦区"<?php if($area=='杨浦区'){ echo 'selected'; } ?>>杨浦区</option>
					<option value="闵行区"<?php if($area=='闵行区'){ echo 'selected'; } ?>>闵行区</option>
					<option value="宝山区"<?php if($area=='宝山区'){ echo 'selected'; } ?>>宝山区</option>
					<option value="嘉定区"<?php if($area=='嘉定区'){ echo 'selected'; } ?>>嘉定区</option>
					<option value="浦东新区"<?php if($area=='浦东新区'){echo 'selected';} ?>>浦东新区</option>
					<option value="金山区"<?php if($area=='金山区'){ echo 'selected'; } ?>>金山区</option>
					<option value="松江区"<?php if($area=='松江区'){ echo 'selected'; } ?>>松江区</option>
					<option value="青浦区"<?php if($area=='青浦区'){ echo 'selected'; } ?>>青浦区</option>
					<option value="南汇区"<?php if($area=='南汇区'){ echo 'selected'; } ?>>南汇区</option>
					<option value="青浦区"<?php if($area=='青浦区'){ echo 'selected'; } ?>>青浦区</option>
					<option value="奉贤区"<?php if($area=='奉贤区'){ echo 'selected'; } ?>>奉贤区</option>
					<option value="崇明县"<?php if($area=='崇明县'){ echo 'selected'; } ?>>崇明县</option>
				</select>
				</span>
			</div>
		</div>
		<div class="cp_name" style="display:none;">详细地址
			<span>
				<input  class="cp_form_input" id="addres_advance" type="text" value="<?php
					if($area && $addressDetails){
						echo $addressDetails;
					}else{
						echo $address;
					}
				?>" name="addres_advance" placeholder="请输入详细地址">
			</span>
		</div>

<!--		<script>-->
<!--			addressInit('Select1', 'Select2', 'Select3');-->
<!--		</script>-->
	<?php endif;?>
<!--2016 .5.19 by 赵鑫-->
	<div id="address_details" style="border-bottom:0px;"></div>


<?php
/*2016 .5.19 by 赵鑫*/
	if($this->type!='advance'){//预售
		$deliverys = $this->preSubmit->deliverys;
		if(empty($deliverys)){
			echo '<script type="text/javascript">location.href="/error"</script>';
		}
		$d = $deliverys;
		echo '
		<div class="floatleft" tig="'.$d->value.'" onclick="javascript:deliveryHelper(this);return false;">'.$d->deliveryTitle.'</div>
		<div id="deliveryMethod'.$d->value.'" class="floatright deliveryMethod"  tig="'.$d->value.'"  onclick="javascript:deliveryHelper(this);return false;">';
		if($d->checked ==1){
			echo '<img src="/images/yigou.png" class="gougou">';
		}else{
			echo '<img src="/images/meigou.png" class="gougou">';
		}
		echo '
		</div>
		';
		if($d->value==1){
			echo '
			<div class="delivery" tig="'.$d->value.'">
				<div style="border-bottom:0px;padding:10px 20px 5px 20px;"><p>自提地址</p>';
				$siteidNameSpace = new Zend_Session_Namespace('siteid');
				$distributerId = $siteidNameSpace->distributerId;
				$distributerName = $siteidNameSpace->distributerName;
				$distributerAddress = $siteidNameSpace->distributerAddress;
				if(!empty($distributerId) && !empty($distributerName) && !empty($distributerAddress)){
					echo '<p id="zitiName" distributerId="'.$distributerId.'" style="text-align:right;padding:0px 5px 0px 0px;">
						'.$distributerName.'
					  </p>
					  <p id="zitiAddress" style="text-align:right;font-size:0.9em;padding:0px 5px 0px 0px;">
						('.$distributerAddress.')
					  </p>
					';
				}else{
					echo '您的自提地址为空，无法完成订单';
				}

				echo '
				</div>
			</div>
			';
		
	}

	if($d->value==2){
		echo '
		<div class="delivery" tig="'.$d->value.'">
			<div style="border-bottom:0px;padding:20px;">送货地址
				<span>
					<input  class="cp_form_input" id="address_songhuo" type="text" value="';
					echo '" name="details_add" placeholder="收货人地址">
				</span>
			</div>
		</div>';
	}
 }//预售
/*2016 .5.19 by 赵鑫*/
?>
<div class="clear"></div>
<!--2016.5.19 by 赵鑫-->
<?php if($this->type!='advance'):?>
	<div class="beijin">&nbsp;</div>
<?php endif; ?>
<!--2016.5.19 by 赵鑫-->
<input type="hidden" id="tom_tod" value="2">
<?php
// var_dump($this->preSubmit);
$deliverys = $this->preSubmit->deliverys;
if(empty($deliverys)){
	echo '<script type="text/javascript">location.href="/error"</script>';
}
$deliveryMethod = $deliverys->delivery;
/*2016.5.19 by 赵鑫 */
if($this->type!='advance') {
	foreach ($deliveryMethod as $t) {
		$val = $t->desc->value;
		echo '<div class="floatleft" tag="' . $val . '" onclick="javascript:deliveryMethodHelper(this);return false;">' . $t->desc->title . '</div>';
		if ($t->desc->checked == 1) {
			echo '<div class="floatright deli shouhuo' . $val . '" tag="' . $val . '" onclick="javascript:deliveryMethodHelper(this);return false;"><img src="/images/yigou.png"  class="gougou dateList"></div>';
		} else {
			echo '<div class="floatright deli shouhuo' . $val . '" tag="' . $val . '" onclick="javascript:deliveryMethodHelper(this);return false;"><img src="/images/meigou.png"  class="gougou dateList"></div>';
		}
	}
}
/*2016.5.19 by 赵鑫 */
if($this->type!='advance') {
	foreach ($deliveryMethod as $t) {
		$val = $t->desc->value;
		$display = $t->desc->timeArrayDisplay;
		echo '<div class="time time' . $val . '" style="border-bottom:0px;padding:20px;display:' . $display . '">预约时间
	<select style="width:150px;height:30px;margin-left:20px;float:right;" class="selectTime" id="appointment' . $val . '">';
		foreach ($t->timeArray->$val as $d) {
			echo '<option class="right_time" value="' . $d->value . '">' . $d->timeTitle . '</option>';
		}
		echo '</select>
	</div>';
	}
}else{
	/*foreach ($deliveryMethod as $t) {
		$val = $t->desc->value;
		$display = $t->desc->timeArrayDisplay;
		echo '<div class="time time' . $val . '" style="border-bottom:0px;padding:20px;display:' . $display . '">发货时间
	<!--<select style="width:150px;height:30px;margin-left:20px;float:right;" class="selectTime" id="appointment' . $val . '">-->';
		foreach ($t->timeArray->$val as $d) {
			//echo '<option class="right_time" value="' . $d->value . '">' . $d->timeTitle . '</option>';
			echo '<label  style="width:120px;height:30px;margin-left:30px;float:right;">'.date('m月d日',strtotime($d->value)+86400).'</label>';
			echo '<input type="hidden" name="svtime" value="'.$d->value.'"  style="width:180px;height:30px;margin-left:20px;float:right;">';
			break;
		}
		echo '<!--</select>-->
	</div>';
	}*/
}
/*2016.5.19 by 赵鑫 */
?>
<script type="text/javascript">
function deliveryMethodHelper(el){
	var tag = $(el).attr('tag');
	$('.deli').html('<img src="/images/meigou.png"  class="gougou dateList">');
	$('.shouhuo'+tag).html('<img src="/images/yigou.png"  class="gougou dateList">');
	$('.time').css('display','none');
	$('.time'+tag).css('display','block');
}
</script>
<div class="clear"></div>
<div class="beijin">&nbsp;</div>

<?php
 if($this->type=='advance') {
	$productDetails = $this->preSubmit->productDetails;
	if(!empty($productDetails)){
			$p = $productDetails;
			echo '
				<div style="float:left;width:30%;text-align:center;padding:5px 0px;">
					<img style="width:80%;max-width:90px;" src="'.$p->imgurl.'">
				</div>
				<div style="float:left;width:50%;padding:5px 0px;color:#242424;">
					<div><span style="font-size:0.9em;">'.$p->skuname.'</span></div>
					<div><span style="font-size:0.9em;">'.$p->spec.'</span></div>
					<div style="margin-top:8px;">
						￥'.$p->price.'
						<span style="background-color:#EC1415;color:white;font-size:0.8em;padding:4px;">返现'.$p->cashBack.'元</span>
					</div>
				</div>
				<div style="float:left;width:18%;padding:5px 0px;color:#242424;padding-top:25px;text-align:center;">
					x'.$p->orderCount.'
					
				</div>
				<div class="clear" style="color:#E71B1E;padding:10px 0px 10px 20px;font-size:0.9em;">'.$p->feature.'</div>
			';
	}
	
 }
?>
<div class="clear"></div>
	<div class="completeRemark">
		<input  style="background-color:#EBEBEB;width:100%;border:0px;padding:5px;" id="remark" type="text" value="" name="remark" placeholder="补充说明：告诉卖家您的特殊需求">
	</div>
<div class="clear"></div>

<div id="user_voucher">
<div class="cp_contact" id="hongbao" onclick="javascript:xiala();return false;" style="margin-left:10px;padding-right:20px;font-size:0.8em;">现金券<span id="hongbao_money"><?php echo $voucher>0?$voucher.'元':'>';?></span></div>
<div class="clear"></div>

<div class="xiala" style="display:none;">
<?php 
	$list = $this->preSubmit->deliverys->voucherList;
	// $list = $this->voucherList;
	$now = floor(time()/86400);
	if(!empty($list)){
		$total = $this->total;
		foreach($list as $l){
			$limit = $l->limit;
			$expired = floor(strtotime($l->expired)/86400) + 1;
			$start = floor(strtotime($l->start)/86400);
			if ($limit<=$custprice && $now<=$expired && $now>=$start){
				echo '
					<div class="wf_hongbao myhb" onclick="javascript:voucherUpdate(this);return false;" tag-id="'.$l->id.'" tag-discount="'.$l->discount.'">
						<input type="hidden" value="'.$l->id.'" id="voucher">
						<div class="wf_left"><span class="jine">'.$l->discount.'元</span></div>
						<div class="wf_right">
							<div class="wf_right1">'.$l->title.'</div>
							<div class="wf_right2">在线支付，满'.$l->limit.'元可用</div>
							<div class="wf_right2">有效期'.$l->start.'至'.$l->expired.'</div>
						</div>
					</div>';
			} else {
				echo '<div class="wf_hongbao_grey myhb" onclick="javascript:voucherUpdate(this);return false;"  tag-id="0" tag-discount="0">
						<input type="hidden" value="0" id="voucher">
						<div class="wf_left_grey"></div>
						<div class="wf_right">
							<div class="wf_right1">'.$l->title.'（暂不可用）</div>
							<div class="wf_right2">在线支付，满'.$l->limit.'元可用</div>
							<div class="wf_right2">有效期'.$l->start.'至'.$l->expired.'</div>
						</div>
					</div>';
			}
		}
	}
?>
<div style="height:30px;">&nbsp;</div>
</div>
</div>
<div class="beijin"></div>

<div style="color:#ACACAC;font-size:0.8em;padding:5px 20px;">请选择支付方式</div>
<?php 
	$payMethods = $this->preSubmit->deliverys->payMethod;
	foreach($payMethods as $p){
		$payTag = $p->value;
		if($p->checkImgStatus==2){
				echo '
				<a href="/personal/topup" style="color:#616161;">
				<div style="border-bottom:1px solid #EAEAEA;">
					<div class="floatleft" style="width:55%;"><img class="zhifu_img" src="'.$p->img.'">&nbsp;
					<span style="position:relative;top:5px;font-size:0.8em;">'.$p->title.'</span>
					<span style="color:red;font-size:0.8em;position:relative;top:5px;">';if($p->balance>=0)echo '('.$p->balance.'元)';echo'</span>
					</div>
					<div class="floatright gou_position" style="width:35%;float:left;font-size:0.8em;color:red;text-align:right;margin-top:5px;border-bottom:0px;">'.$p->msg.'</div>
					<div class="clear"></div>
				</div></a>';
		}else{
			if($payTag ==2 && isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false){
				echo '
					<div tag="'.$p->value.'" onclick="javascript:payHelper(this);return false;">
						<div class="floatleft">
							<img class="zhifu_img" src="'.$p->img.'">&nbsp;
							<span style="position:relative;top:5px;font-size:0.8em;">'.$p->title.'</span>
							<span style="color:red;font-size:0.8em;position:relative;top:5px;">';if($p->balance>=0)echo '('.$p->balance.'元)';echo'</span>
						</div>
						<div class="floatright gou_position payGou" id="pay'.$p->value.'">';
						if($p->checked==1){
							echo '<img src="/images/yigou.png" class="gougou" id="checkedImg" tag="'.$p->value.'"></div>';
						}else{
							echo '<img src="/images/meigou.png" class="gougou"></div>';
						}
						echo'	<div class="clear"></div>
						</div>';
				}
			if($payTag!=2){
				echo '
					<div tag="'.$p->value.'" onclick="javascript:payHelper(this);return false;">
						<div class="floatleft">
							<img class="zhifu_img" src="'.$p->img.'">&nbsp;
							<span style="position:relative;top:5px;font-size:0.8em;">'.$p->title.'</span>
							<span style="color:red;font-size:0.8em;position:relative;top:5px;">';if($p->balance>=0)echo '('.$p->balance.'元)';echo'</span>
						</div>
						<div class="floatright gou_position payGou" id="pay'.$p->value.'">';
						if($p->checked==1){
							echo '<img src="/images/yigou.png" class="gougou" id="checkedImg" tag="'.$p->value.'"></div>';
						}else{
							echo '<img src="/images/meigou.png" class="gougou"></div>';
						}
				echo'	<div class="clear"></div>
				</div>';
			}
		}
	}
?>
<script type="text/javascript">
function payHelper(el){
	var tag = $(el).attr('tag');
	$('.payGou').html('<img src="/images/meigou.png" class="gougou">');
	$('#pay'+tag).html('<img src="/images/yigou.png" class="gougou">');
	if(tag>1){
		$('#payment').val(2);
	}else{
		$('#payment').val(1);
	}
	$('#pay_int').val(tag);
}
</script>
<input type="hidden" id="payment" value="2">
<input type="hidden" id="pay_int" value="2">


<div class="clear"></div>




<div class="cp_total" style="display:none;">商品总额
	<span>￥<span  id="total_cart"><?php echo $price?></span></span>
</div>
<?php 
	if(!empty($discount)&&Floatval($discount)>0){
		echo '<div class="cp_total">满减折扣
				<span>￥<span id="zhekou">'.$discount.'</span></span>
			</div>';
	}
	if ($voucher > 0 && $voucherId > 0) {
		echo '
		<div id="hb_holder" class="cp_total"  style="display:none">现金券抵扣
			<span>￥<span id="dikou">'.$voucher.'</span></span>
			<input type="hidden" value="'.$voucherId.'" id="voucherId" name="voucherId">
		</div>';
	} else {
		echo '
		<div id="hb_holder" class="cp_total" style="display:none">现金券抵扣
			<span>￥<span id="dikou">0</span></span>
			<input type="hidden" value="0" id="voucherId" name="voucherId">
		</div>';
	}
	if(!empty($gift)){
		echo '<div class="cp_total">卖家赠品
				<span><span>'.$gift.'</span></span>
			</div>';
	}
	echo '<input type="hidden" id="custprice" value="'.$custprice.'">
		<input type="hidden" id="iszeing" value="no" time-limit="'.$time_end.'">
		<input type="hidden" id="presell" value="0">
		<!--<div id="youhui" class="cp_total cp_zhi" style="border-bottom:0px;display:none;">明日预约
			<span><span>9.5折优惠</span></span>
		</div>
		<div class="cp_total cp_zhi" style="border-bottom:0px;">还需支付
			<span>￥<span id="leftpay">'.$custprice.'</span></span>
		</div>-->
	';
?>



<div class="error_msg" style="color:red;text-align:center;"></div>
<!--<input type="button" id="confirm_pay" class="cp_btn confirmpay " value="提交订单" style="border:0px;margin-bottom:20px;" >--><!---onclick="javascript:confirmpay();return false;"--->
<div style="height:50px;width:100%;">&nbsp;</div>
</div>
</div>
<div class="fixDiv">
	<div style="width:60%;float:left;padding:15px 0px 15px 15px;">
		应付：￥<span id="leftpay" style="color:red;"><?php echo $custprice;?></span></div>
	<div style="float:left;width:40%;">
		<input id="confirm_pay" class="completeBut confirmpay" type="button" value="提交订单">
	</div>
</div>
<div class="clear"></div>
</form>

<script type="text/javascript">
var myScroll='';
 $(document).ready(function(){
	if($('#yue_zhifu').length>0){
		zhfu_yue();
	}else if($('#weixin_zhifu').length>0 && $('#yue_zhifu').length==0){
		zhfu_weixin();
	}
	var checkedImgTag = $('#checkedImg').attr('tag');
	if(checkedImgTag>1){
		$('#payment').val(2);
	}else{
		$('#payment').val(1);
	}
	$('#pay_int').val(checkedImgTag);
	myScroll = new iScroll('wrapperCom', { scrollbarClass: 'myScrollbar' });
	//支付
	$('.confirmpay').click(function(){
		confirmpay();
	});

});

function xiala(){
	var lenVoucher = $('.myhb').length;
	if(lenVoucher>0){
		$('.xiala').toggle();
		refreshScroll();
	}else{
		alert('暂无可用现金券！');
	}
	
}
function voucherUpdate(el){
	voucherId = el.getAttribute('tag-id');
	voucherDiscount = el.getAttribute('tag-discount');
	if(iszeing=='yes'){
		updatePrice(voucherId,voucherDiscount,zekou);
	}else{
		updatePrice(voucherId,voucherDiscount,1);
	}
	$('.xiala').hide();
	refreshScroll();
}
function refreshScroll(){
	setTimeout(function () {
		myScroll.destroy();
		myScroll = '';
		myScroll = new iScroll('wrapperCom', { scrollbarClass: 'myScrollbar' });
		var height = $('#hongbao')[0].offsetTop;
		myScroll.scrollTo(0,0,0,true);
	}, 10);
}
init_iszeing();
$('#remark').blur(function(){
	refreshScroll();
});

</script>
